#导入相关的页面类
import allure
from page.page_index import PageIndex
from page.page_login import PageLogin
from page.page_user import PageUser

#登录业务
class ServerLogin(object):

    def __init__(self,driver):
        #初始化相关的页面类对象
        self.page_index=PageIndex(driver)
        self.page_login=PageLogin(driver)
        self.page_user=PageUser(driver)


    def service_login_001(self,d):
        # “首页”上控件
        allure.attach("","步骤1：打开首页")
        self.page_index.openUrl()
        allure.attach("", "步骤2：点击登录按钮")
        self.page_index.click_login()
        # “登录”上控件
        allure.attach("",f"步骤3：输入账号:{d['zanhao']}")
        self.page_login.input_zanhao(d["zanhao"])
        self.page_login.input_pwd(d["pwd"])
        self.page_login.click_login()
        # 部分3：断言
        siji=self.page_user.getNiCenText()
        tupianName=self.page_user.savePng("登录",d["key"]) #"登录_Key01_202401011000.png"
        allure.attach(open(f'./screen/{tupianName}', 'rb').read(), "步骤n:本次截图", allure.attachment_type.PNG)
        return siji == d["yuqi"]

    def service_login_002(self,d):
        # “首页”上控件
        self.page_index.openUrl()
        self.page_index.click_login()
        # “登录”上控件
        self.page_login.input_zanhao(d["zanhao"])
        self.page_login.input_pwd(d["pwd"])
        self.page_login.click_login()
        # 部分3：断言
        siji=self.page_login.getErrorTipText()
        return siji == d["yuqi"]

    def service_login_003(self,d):
        # “首页”上控件
        self.page_index.openUrl()
        self.page_index.click_login()
        # “登录”上控件
        self.page_login.input_zanhao(d["zanhao"])
        self.page_login.input_pwd(d["pwd"])
        self.page_login.click_login()
        # 部分3：断言
        siji=self.page_login.getZanhaoClassAttr()
        return d["yuqi"] in siji

    def service_login_004(self,d):
        # “首页”上控件
        self.page_index.openUrl()
        self.page_index.click_login()
        # “登录”上控件
        self.page_login.input_zanhao(d["zanhao"])
        self.page_login.input_pwd(d["pwd"])
        self.page_login.click_login()
        # 部分3：断言
        siji=self.page_login.getMimaClassAttr()
        return d["yuqi"] in siji
